using System;
using System.Xml;

namespace umbracoRss.BusinessLogic
{
	/// <summary>
	/// Summary description for Tree.
	/// </summary>
	public class Tree : umbraco.interfaces.ITree
	{
		public Tree()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		#region TreeI Members

		private int _id;
		private string _app;

		public int id 
		{
			set {_id = value;}
		}
		public string app
		{
			set {_app = value;}
		}

		public void RenderJS(ref System.Text.StringBuilder Javascript) 
		{
			Javascript.Append(@"
function openRss(id) {
	parent.right.document.location.href = 'plugins/rss/editRss.aspx?id=' + id;
}
");
		}

		public void Render(ref XmlDocument Tree) 
		{
			
			XmlNode root = Tree.DocumentElement;

			foreach (RssInstance r in RssInstance.GetAll())
			{
				XmlElement treeElement = Tree.CreateElement("tree");
				treeElement.SetAttribute("nodeID", r.Id.ToString());
				treeElement.SetAttribute("text", r.Title);
				treeElement.SetAttribute("action", "javascript:openRss('" + r.Id.ToString() + "');");
				treeElement.SetAttribute("menu", "D");
				treeElement.SetAttribute("src", "");
				treeElement.SetAttribute("icon", "settingXML.gif");
				treeElement.SetAttribute("openIcon", "settingXML.gif");
				treeElement.SetAttribute("nodeType", "rssInstance");
				root.AppendChild(treeElement);			
			}
		}
		#endregion
	}
}
